import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { DashboardService } from './dashboard.service';
import swal from 'sweetalert2';

@Component({
  selector: 'app-dashboard',
  templateUrl: './dashboard.component.html',
  styleUrls: ['./dashboard.component.scss']
})
export class DashboardComponent implements OnInit {
  projectOverView: any = {};
  constructor(
    private router: Router,
    private service: DashboardService
  ) { }

  ngOnInit() {
    this.getProjectOverview();
  }

  getProjectOverview() {
    this.service.getProjectOverview()
      .then((data: any) => {
        this.projectOverView = data;
      });
  }

  logout() {
    swal({
      title: '',
      text: '确定退出?',
      showCancelButton: true,
      confirmButtonColor: '#fff',
      cancelButtonColor: '#fff',
      confirmButtonText: '确定',
      cancelButtonText: '取消'
    }).then((isConfirm) => {
      if (isConfirm) {
        localStorage.clear();
        this.router.navigate(['mobile-layout/login']);
      }
    }).catch(swal.noop);
  }

  goTo() {
    this.router.navigate(['/mobile-layout/itemlist']);
  }

}
